<?php

namespace App\Http\Controllers\Admin;

use App;
use App\Http\Controllers\Controller as BaseController;
use App\Common\Status;
use App\Http\Logic\Admin\PositionCategoryLogic;
use App\Http\Requests\PositionCategoryRequest;
use Illuminate\Http\Request;

class PositionCategoryController extends BaseController
{

    /**
     * @return \Illuminate\Http\JsonResponse
     */
    public function list(Request $request): \Illuminate\Http\JsonResponse
    {
        $params = $request->query();
        $data   = PositionCategoryLogic::getCategoryList($params);
        return $this->success(Status::SUCCESS, 'success', $data);
    }


    /**
     * @param PositionCategoryRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function createCategory(PositionCategoryRequest $request): \Illuminate\Http\JsonResponse
    {
        $params = $request->validated();
        $id     = PositionCategoryLogic::createCategory($params);
        $r      = $params['id'] ? [] : ['id' => $id];
        return $this->success(Status::SUCCESS, 'success', $r);
    }


    /**
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function dtlCategory($id)
    {
        $info = PositionCategoryLogic::getCategoryDtl($id);
        return $this->success(Status::SUCCESS, 'success', $info);
    }


    /**
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function delCategory($id): \Illuminate\Http\JsonResponse
    {
        PositionCategoryLogic::delCategory($id);
        return $this->success(Status::SUCCESS, 'success', []);
    }
}
